package com.th.coupon.common.constant;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 优惠卷类型
 * @author 涂航
 */
@AllArgsConstructor
@Getter
public enum CouponCategory {

    ALLMINUS("满减卷","001"),
    SETUPMINUS("立减卷","002"),
    DISCOUNT("折扣卷","003");

    /**
     * 优惠卷描述
     */
    private String description;
    /**
     * 优惠卷码
     */
    private String code;

    public static CouponCategory of(String code){
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code +" not exists !!!"));
    }

}
